package com.macrolab.secure.softhsm;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import sun.security.pkcs11.SunPKCS11;

import java.io.File;
import java.security.*;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;

public class MyTest4SoftHSM {

    public static void main(String[] args) throws Exception {

        File cfgFile = new File("D:\\my\\workspace\\softhsm-1\\src\\main\\resources\\softhsm.cfg");
        String userPin = "2wsx";
        SoftHSMUtils.init(cfgFile.getAbsolutePath(), userPin);

        Security.addProvider(new BouncyCastleProvider());

        for (Provider p : Security.getProviders()) {
            System.out.println("provider name: " + p.getName() + "  ver: " + p.getVersion());
            System.out.println("provider info: " + p.getInfo());
             System.out.println("\n");
        }
        System.out.println("----------------------------------------");
        KeyPair kp = SoftHSMUtils.generateKeyPair("RSA", 2048);
        System.out.println("public  key: " + kp.getPublic());
        System.out.println("private key: " + kp.getPrivate());

    }


}
